<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改菜单')"/>
    <th:block th:include="include :: select2-css"/>

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-department-edit" th:object="${departments }">
        <input id="depID" name="depID" type="hidden" th:field="*{depID}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门编号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="depCode" id="depCode" th:field="*{depCode}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="title" id="title" th:field="*{title}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门简称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="depAbbr" id="depAbbr" th:field="*{depAbbr}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">所属公司：</label>
            <div class="col-sm-8">
                <select id="compID" name="compID" class="form-control" th:onchange="getbumen(this.value)">
                    <option th:each="Allcompany:${Allcompanys}" th:value="${Allcompany.compID}"
                            th:text="${Allcompany.title}" th:field="*{compID}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级部门：</label>
            <div class="col-sm-8">
                <select id="adminID" name="adminID" class="form-control">
                    <option th:each="DepartmentAll:${DepartmentAll}" th:value="${DepartmentAll.depID}"
                            th:text="${DepartmentAll.title}" th:field="*{adminID}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门级别：</label>
            <div class="col-sm-8">
                <select name="depGrade" id="depGrade" class="form-control"
                        th:with="type=${@dict.getType('oCD_DepGrade')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{depGrade}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门类型：</label>
            <div class="col-sm-8">
                <select name="depType" id="depType" class="form-control"
                        th:with="type=${@dict.getType('oCD_DepType')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{depType}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门属性：</label>
            <div class="col-sm-8">
                <select name="depProperty" id="depProperty" class="form-control"
                        th:with="type=${@dict.getType('oCD_DepProperty')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{depProperty}"></option>
                </select>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>

<script type="text/javascript">

    function edit() {
        var depID = $("input[name='depID']").val();
        var depCode = $("input[name='depCode']").val();
        var title = $("input[name='title']").val();
        var depAbbr = $("input[name='depAbbr']").val();
        var compID = $("#compID").val();
        var adminID = $("#adminID").val();
        var depGrade = $("#depGrade").val();
        var depType = $("#depType").val();
        var depProperty = $("#depProperty").val();

        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "department/edit",
            data: {
                "depID": depID,
                "depCode": depCode,
                "title": title,
                "depAbbr": depAbbr,
                "compID": compID,
                "adminID": adminID,
                "depGrade": depGrade,
                "depType": depType,
                "depProperty": depProperty
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }


    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }


    function getbumen(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findDep",
            data : {
                "compID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#adminID").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].depID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#adminID").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:"  + textStatus);
            }
        });
    }
</script>

</body>
</html>
